Namespace FuncionesString
    Public Module mdNumerosLetras
        Public Function letrasaNumerosIngles(ByVal letras As String, ByVal base As Integer) As Integer
            If base > 26 Then Throw New clErrorPersonalizado("La base no puede ser mayor de 26 ya que no hay suficientes letras")
            Dim i As Integer
            Dim aux As Integer
            Dim ponderacion As Integer
            Dim letra As String
            Dim texto As String = letras.ToUpper
            Dim k As Integer = 0
            For i = letras.Length - 1 To 0 Step -1
                letra = texto.Substring(i, 1)
                ponderacion = CInt(Math.Pow(base, k))
                'If ponderacion = 0 Then ponderacion = 1
                aux += valoresLetras(letra) * ponderacion
                k += 1
            Next
            Return aux
        End Function
        Public Function NumerosLetrasIngles(ByVal valor As Integer, ByVal base As Integer) As String
            Dim resultado As Integer
            Dim sobra As Int32
            Dim aux As String
            resultado = valor
            Do
                resultado = resultado \ base
                sobra = valor Mod base
                If sobra = 0 Then
                    aux = letrasAValores(base) & aux
                    resultado -= 1
                Else
                    aux = letrasAValores(sobra) & aux
                End If

                valor = resultado
            Loop Until resultado = 0
            Return aux
        End Function

        Private Function valoresLetras(ByVal letra As String) As Integer
            Dim aux As Integer
            aux = Asc(letra.ToUpper) - 64
            Return aux
        End Function

        Private Function letrasAValores(ByVal valor As Integer) As String
            Dim aux As String
            valor += 64
            aux = Chr(valor)
            Return aux
        End Function

    End Module
End Namespace